<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('approvals', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('company_id')->default(0)->index();
            $table->unsignedBigInteger('project_id')->comment('项目ID');
            $table->unsignedBigInteger('flow_id')->comment('使用的审批流程ID');
            $table->string('title', 100)->nullable()->comment('审批标题');
            $table->string('content')->nullable()->comment('审批内容描述');
            $table->string('model')->comment('模块');
            $table->string('source')->comment('来源');
            $table->unsignedBigInteger('source_id')->default(0)->comment('来源ID');
            $table->string('status')->default('afoot')->comment('审批状态：afoot-审批中 approved-已通过 rejected-已驳回 transfer-转审');
            $table->unsignedBigInteger('current_node_id')->nullable()->comment('当前审批节点ID');
            $table->unsignedBigInteger('current_record_id')->nullable()->comment('当前审批节点ID');
            $table->unsignedBigInteger('role_id')->default(0)->comment('当前审批角色');
            $table->unsignedBigInteger('admin_id')->default(0)->comment('当前审批人');
            $table->unsignedBigInteger('created_by')->default(0)->index()->comment('申请人ID');
            $table->unsignedBigInteger('level_count')->default(0)->index()->comment('层级数');
            $table->timestamp('approved_at')->nullable()->comment('最终审批通过时间');
            $table->timestamp('rejected_at')->nullable()->comment('最终审批驳回时间');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('approvals');
    }
};
